package com.shop2cn.iapi.accounting.testcase;

import java.util.HashMap;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.accounting.parameter.AccountEntryBean;
import com.shop2cn.iapi.accounting.parameter.GetAccountEntryBean;
import com.shop2cn.iapi.accounting.service.GetAccountEntryCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.database.model.AccountEntry;
import com.ymttest.database.sqlwapper.AccountWapper;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 获取账户资金流水接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetAccountEntry {
	private static GetAccountEntryBean getaccountentryBean;
	private static GetAccountEntryCall getaccountentryCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取账户资金流水接口");
		getaccountentryBean = new GetAccountEntryBean();
		getaccountentryCall = new GetAccountEntryCall();

	}

	@Before
	public void caseUp() {
		getaccountentryBean = new GetAccountEntryBean();
		getaccountentryCall = new GetAccountEntryCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getaccountentryCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@SuppressWarnings("rawtypes")
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetAccountEntry_001() {
		Logger.start(true, "获取账户资金流水成功");
		try {
			List<HashMap>m=new AccountWapper().selectAccountEntryAndInfo();
			Logger.debug(m);
			int index=0;
			int userId = (Integer) m.get(index).get("UserId");
			int type = (Integer) m.get(index).get("AccountType");
			int bizCode = (Integer) m.get(index).get("BizCode");
			String bizNo = (String) m.get(index).get("BizNo");
			int entryType = (Integer) m.get(index).get("EntryType");
			String appId = (String) m.get(index).get("AppId");
			getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			getaccountentryBean.setAppId(appId);
			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();
			// 查询数据库
			List<AccountEntry> dbEntry = new AccountWapper().selectAccountEntry(userId, bizNo, type);
			// Logger.debug(FormatUtil.beanToGSONString(dbEntry));
			// 接口返回数据
			AccountEntryBean retrunData = getaccountentryCall.getReturnAccountEntry();
			Logger.verifyEquals(0, getaccountentryCall.getStatuscode(), "验证code");

			Logger.verifyEquals(dbEntry.get(0).getAccountId(), retrunData.getAccountId(), "验证接口返回AccountId跟数据库是否一致");
			Logger.verifyEquals(dbEntry.get(0).getEntryId(), retrunData.getEntryId(), "验证接口返回EntryId跟数据库是否一致");
			Logger.verifyEquals(0, dbEntry.get(0).getAmount().compareTo(retrunData.getAmount()), "验证接口返回Amount:" + retrunData.getAmount() + "跟数据库是否一致");
			Logger.verifyEquals(0, dbEntry.get(0).getFreezeAmount().compareTo(retrunData.getFreezeAmount()), "验证接口返回FreezeAmount:" + retrunData.getFreezeAmount() + "跟数据库是否一致");
			Logger.verifyEquals(0, dbEntry.get(0).getAvailAmount().compareTo(retrunData.getAvailAmount()), "验证接口返回AvailAmount:" + retrunData.getAvailAmount() + "跟数据库是否一致");
			Logger.verifyEquals(dbEntry.get(0).getEntryType(), retrunData.getEntryType(), "验证接口返回EntryType跟数据库是否一致");
			Logger.verifyEquals(dbEntry.get(0).getUserId(), retrunData.getUserId(), "验证接口返回UserId跟数据库是否一致");
			Logger.verifyEquals(dbEntry.get(0).getBizCode(), retrunData.getBizCode(), "验证接口返回BizCode跟数据库是否一致");
			Logger.verifyEquals(dbEntry.get(0).getBizNo(), retrunData.getBizNo(), "验证接口返回BizNo跟数据库是否一致");
			Logger.verifyEquals(dbEntry.get(0).getOriginalNo(), retrunData.getOriginalNo(), "验证接口返回OriginalNo跟数据库是否一致");
			Logger.verifyEquals(YMTDateUtil.getFormatTime(dbEntry.get(0).getAccountingDate(), "yyyy-MM-dd HH:mm:ss"), retrunData.getAccountingDate(),
					"验证接口返回AccountingDate跟数据库是否一致");

			Logger.verifyEquals(YMTDateUtil.getFormatTime(dbEntry.get(0).getUpdateTime(), "yyyy-MM-dd HH:mm:ss"), retrunData.getUpdateTime(), "验证接口返回UpdateTime跟数据库是否一致");
			Logger.verifyEquals(YMTDateUtil.getFormatTime(dbEntry.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss"), retrunData.getCreateTime(), "验证接口返回CreateTime跟数据库是否一致");

			Logger.verifyEquals(dbEntry.get(0).getOperator(), retrunData.getOperator(), "验证接口返回Operator跟数据库是否一致");
			Logger.verifyEquals(dbEntry.get(0).getMemo(), retrunData.getMemo(), "验证接口返回Memo跟数据库是否一致");
			Logger.verifyEquals(dbEntry.get(0).getAppId(), retrunData.getAppId(), "验证接口返回AppId跟数据库是否一致");
			Logger.verifyEquals(dbEntry.get(0).getServerIp(), retrunData.getServerIp(), "验证接口返回ServerIp跟数据库是否一致");
			Logger.verifyEquals(dbEntry.get(0).getClientIp(), retrunData.getClientIp(), "验证接口返回ClientIp跟数据库是否一致");
			Logger.verifyEquals(dbEntry.get(0).getRequestId(), retrunData.getRequestId(), "验证接口返回RequestId跟数据库是否一致");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings("rawtypes")
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountEntry_002() {
		Logger.start(false, "账户类型不存在,获取资金流水为空");
		try {
			List<HashMap>m=new AccountWapper().selectAccountEntryAndInfo();
			int index=0;
			int userId = (Integer) m.get(index).get("UserId");
			int type = 9;
			int bizCode = 100001;
			String bizNo = "4352f30d-7c15-4de5-8957-635bf1000020926";
			int entryType = 1;
			String appId = "StressTest";
			getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			getaccountentryBean.setAppId(appId);

			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();

			Logger.verifyEquals(2, getaccountentryCall.getStatuscode(), "验证code");
			Logger.verifyIsContains(ECode.ACCOUNTTYPE_NOT_NULL, getaccountentryCall.getMsg(), "验证msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings("rawtypes")
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountEntry_003() {
		Logger.start(false, "业务编码不存在,,获取资金流水返回为空");
		try {
			
			List<HashMap>m=new AccountWapper().selectAccountEntryAndInfo();
			int index=0;
			int userId = (Integer) m.get(index).get("UserId");
			int type = (Integer) m.get(index).get("AccountType");
			
			int bizCode = 900002;
			String bizNo = "4352f30d-7c15-4de5-8957-635bf1000020926";
			int entryType = 1;
			String appId = "StressTest";
			getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			getaccountentryBean.setAppId(appId);

			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();

			Logger.verifyEquals(0, getaccountentryCall.getStatuscode(), "验证code");
			Logger.verifyIsNull(getaccountentryCall.getData(), "验证返回data为null");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings("rawtypes")
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountEntry_004() {
		Logger.start(false, "业务流水号不存在,,获取资金流水返回为空");
		try {
			List<HashMap>m=new AccountWapper().selectAccountEntryAndInfo();
			int index=0;
			int userId = (Integer) m.get(index).get("UserId");
			int type = (Integer) m.get(index).get("AccountType");
			
			
			int bizCode = 100001;
			String bizNo = "4352f30d-7c15-";
			int entryType = 1;
			String appId = "StressTest";
			getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			getaccountentryBean.setAppId(appId);

			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();

			Logger.verifyEquals(0, getaccountentryCall.getStatuscode(), "验证code");
			Logger.verifyIsNull(getaccountentryCall.getData(), "验证返回data为null");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings("rawtypes")
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountEntry_005() {
		Logger.start(false, "流水类型不存在,,获取资金流水返回为空");
		try {
			List<HashMap>m=new AccountWapper().selectAccountEntryAndInfo();
			int index=0;
			int userId = (Integer) m.get(index).get("UserId");
			int type = (Integer) m.get(index).get("AccountType");
			int bizCode = 100001;
			String bizNo = "4352f30d-7c15-4de5-8957-635bf100002092";
			int entryType = 1;
			String appId = "StressTest";
			getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			getaccountentryBean.setAppId(appId);

			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();

			Logger.verifyEquals(0, getaccountentryCall.getStatuscode(), "验证code");
			Logger.verifyIsNull(getaccountentryCall.getData(), "验证返回data为null");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	// @Test
	@SuppressWarnings("rawtypes")
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountEntry_006() {
		Logger.start(false, "应用编号不存在,,获取资金流水返回为空");
		try {
			List<HashMap>m=new AccountWapper().selectAccountEntryAndInfo();
			int index=0;
			int userId = (Integer) m.get(index).get("UserId");
			int type = (Integer) m.get(index).get("AccountType");
			int bizCode = (Integer) m.get(index).get("BizCode");
			String bizNo = (String) m.get(index).get("BizNo");
			int entryType = (Integer) m.get(index).get("EntryType");
			
			String appId = "xxx";
			getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			getaccountentryBean.setAppId(appId);

			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();

			Logger.verifyEquals(0, getaccountentryCall.getStatuscode(), "验证code");
			Logger.verifyIsNull(getaccountentryCall.getData(), "验证返回data为null");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountEntry_007() {
		Logger.start(false, "用户id为空,,获取资金流水返回为空");
		try {
			int type = 0;
			int bizCode = 100001;
			String bizNo = "4352f30d-7c15-4de5-8957-635bf100002092";
			int entryType = 1;
			String appId = "StressTest";
			// getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			getaccountentryBean.setAppId(appId);

			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();

			Logger.verifyEquals(ECode.ACCOUNT_NOT_FOUND_CODE, getaccountentryCall.getStatuscode(), "验证code");
			Logger.verifyEquals(ECode.ACCOUNT_NOT_EXIST, getaccountentryCall.getMsg(), "验证msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountEntry_008() {
		Logger.start(false, "AppId为空,,获取资金流水返回为空");
		try {
			int userId = 319;
			int type = 0;
			int bizCode = 100001;
			String bizNo = "4352f30d-7c15-4de5-8957-635bf100002092";
			int entryType = 1;
			getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			// getaccountentryBean.setAppId(appId);

			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();

			Logger.verifyEquals(2, getaccountentryCall.getStatuscode(), "验证code");
			Logger.verifyEquals("AppId不能为空！", getaccountentryCall.getMsg(), "验证msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}